import os
import textwrap
import time

import google.generativeai as genai
import PIL.Image

from IPython.display import Markdown

genai.configure(api_key = 'AIzaSyCYKdkqTOdlmjdauzFVDoFz_rEYwsazTH0')

def to_markdown(text):
  text = text.replace('•', '  *')
  return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))

model = genai.GenerativeModel('gemini-pro-vision')

files = os.listdir("/Users/yuwang/Desktop/Gemini in Political Science/data/images")

def image_analysis(image_name):
    print("Image name", image_name)
    img = PIL.Image.open("./../data/images/" + image_name)
    # img = PIL.Image.open("/Users/yuwang/Downloads/_132488714_mediaitem132488713.jpg.webp")
    # prompt = 'Describe the facial expression of the main character that you can detect from the image. Also list evidence behind your reasoning.'
    # prompt = "Describe the eyes of the main character that you can detect from the image."
    prompt = "List the known politicians in the given image."
    #prompt = "Describe the facial expressions in this picture?"
    response = model.generate_content([prompt, img])
    print("response.prompt_feedback", response.prompt_feedback)
    print("response.text", response.text)
    #print("====" * 10)


image_analysis("cbs-news_0000_9.jpg")
image_analysis("abc-news_0003_4.jpg")
